#ifndef FORM_H
#define FORM_H

#include <QWidget>
#include "tcp_server.h"

namespace Ui {
class Form;
}

class Form : public QWidget
{
    Q_OBJECT

public:
    explicit Form(QWidget *parent = nullptr);
    ~Form();

private:
    Ui::Form *ui;

private:
    //服务器状态
    bool isOk;
    //tcp服务器
    TcpServer *m_server;

private slots:
    void initForm();

    void append(int type, const QString &data, bool clear = false);

private slots:
    void clientConnected(const QString &ip, int port);
    void clientDisconnected(const QString &ip, int port);
    void sendData(const QString &ip, int port, const QString &data);
    void receiveData(const QString &ip, int port, const QString &data);

private slots:
    //监听或者关闭服务器
    void on_btnListen_clicked();
    //清空显示数据
    void on_btnClear_clicked();
    //发送数据
    void on_btnSend_clicked();
    //关闭某个客户端连接
    void on_btnClose_clicked();
};

#endif // FORM_H
